module.exports = function ($scope, $state, $resource, $modal, toaster) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
	};
	$scope.pageInfo = {};
	$scope.pageInfo.pageNo = 1;		//当前页码
	$scope.pageInfo.pageSize = 10;	//每页显示几条
	$scope.pageInfo.totalItems = 0;	//总条数
	//列表
	$scope.loadlist = function () {
		$resource('/api/as/mc/shopproduct/findProductFlashSalePageList', {}, {}).save($scope.pageInfo, function (res) {
			if (res.errcode === 0) {
				$scope.beanList = res.data.results;
				$scope.pageInfo.totalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}

	$scope.loadlist();

		//查看
        $scope.gatInfo = function(addinfo) {
            addinfo.openstate = true;
            addinfo.hisstate = true;
            addinfo.examinestate = false;
            var modalInstance = $modal.open({
                template: require('../views/addFlashsale.html'),
                controller: 'addFlashsale',
                size: 'lg',
                resolve: {
                    item : function () {
                        return addinfo;
                    },
                    flag : function () {
                        return addinfo == 1;
                    }
                }
            });
            //关闭模态框刷新页面
            modalInstance.result.then(function() {
                $scope.loadlist();
            });
        }


	//添加or修改
	$scope.add = function(info) {
    if (info != '1'){
      info.openstate = false;
    } 
    console.log(info);
		var modalInstance = $modal.open({
			template: require('../views/addFlashsale.html'),
			controller: 'addFlashsale',
			size: 'lg',
			resolve: {
				item : function () {
					return info;
        },
				flag : function () {
					return info == 1;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function() {
			$scope.loadlist();
		});
	}





	//删除
	$scope.delete = function (bean) {
		if (confirm('确认删除此条记录吗？') == true) {
			$resource('/api/as/mc/shopproduct/updatedelflashsale', {}, {}).save(bean, function (res) {
				if (res.errcode === 0) {
					$scope.loadlist();
				} else {
					toaster.error({ title: '', body: res.errmsg });
				}
			});
		}
	}

};